package com.foreknow.proxy.one;

/**
 * 代理公司  物流公司
 */
public class CompanyProxy implements SuperMarketAction {
    private SuperMarket superMarket;

    public CompanyProxy(SuperMarket superMarket) {
        this.superMarket = superMarket;
    }

    @Override
    public void deliverGoods() {
        System.out.println("调用方法之前要做的操作");
        superMarket.deliverGoods();
        System.out.println("调用方法之后要做的操作");
    }

    @Override
    public void test() {
        System.out.println("调用方法之前要做的操作");
        superMarket.deliverGoods();
        System.out.println("调用方法之后要做的操作");
    }

    public static void main(String[] args) {
        //如果不使用代理模式
        //SuperMarket superMarket = new SuperMarket();
        //superMarket.deliverGoods();

        //如果使用代理类
        SuperMarket superMarket = new SuperMarket();
        CompanyProxy proxy = new CompanyProxy(superMarket);
        proxy.deliverGoods();
    }
}
